﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.Utils;
using Ccit.Utils;

namespace Ccit.OA.NewsCenter
{
    public partial class news_inform_view : Ccit.Utils.Page
    {
        LoginUser loginUser = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loginUser = (LoginUser)Session["LogUserInfo"];
                hdNewsId.Value = (null != Request.QueryString["Id"]) ? Request.QueryString["Id"].ToString() : "";
                InitPage();
            }
        }

        private void InitPage()
        {
            string sId = hdNewsId.Value;
            if (sId != "")
            {
                MsViewInfo msViewInfo = new MsViewInfo();
                msViewInfo.NewsId = sId;
                msViewInfo.UserId = loginUser.UserId;
                msViewInfo.BeginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                msViewInfo.EndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");                
                SubmitBLL oSubmit = new SubmitBLL();
                if (oSubmit.SaveViewRecord(msViewInfo))
                {
                    MsNews msNews = oSubmit.GetNewsByNewsId(sId);
                    hdNewsId.Value = msNews.NewsId;
                    lblCreator.Text = SysInterface.GetNameStrByIdStr(msNews.IssueUserId, NameType.USER, ",");
                    lblCreateTime.Text = msNews.IssueDate;
                    tdNewsTitle.InnerText = msNews.NewsTitle;
                    lblDiscussCount.Text = msNews.CommentCount;
                    string sColumnName = SysInterface.GetNameStrByIdStr("NEWS_A2", "NEWS_A2_10", "NEWS_A2_20", msNews.ColumnNo, ",");
                    tdColumnName.InnerHtml = (sColumnName != "") ? sColumnName : "&nbsp;";
                    string sNewsSet = "";
                    if (msNews.TopFlag == "1")
                    {
                        sNewsSet += "信息置顶";
                    }
                    if (msNews.CommentFlag == "1")
                    {
                        if (sNewsSet != "")
                            sNewsSet += ",";
                        sNewsSet += "允许发表评论";
                        haDiscuss.Style["display"] = "block";
                    }
                    else
                    {
                        haDiscuss.Style["display"] = "none";
                    }
                    if (msNews.PicFlag == "1")
                    {
                        if (sNewsSet != "")
                            sNewsSet += ",";
                        sNewsSet += "有导航图片";
                    }
                    tdNewsSet.InnerHtml = (sNewsSet != "") ? sNewsSet : "&nbsp;";
                    string sContentType = msNews.ContentFormat;
                    hdContentType.Value = sContentType;
                    if (sContentType == "1")
                    {
                        tdContentType.InnerText = "WORD";
                        InitOffice("1");
                        trHtmlContent.Style["display"] = "none";
                        trUrl.Style["display"] = "none";
                        EDITOR_WORD.Style["display"] = "block";
                    }
                    else if (sContentType == "2")
                    {
                        tdContentType.InnerText = "EXCEL";
                        InitOffice("2");
                        trHtmlContent.Style["display"] = "none";
                        trUrl.Style["display"] = "none";
                        EDITOR_WORD.Style["display"] = "block";
                    }
                    else if (sContentType == "0")
                    {
                        tdContentType.InnerText = "HTML";
                        tdContent.InnerHtml = (msNews.NewsContent != "") ? msNews.NewsContent : "&nbsp;";
                        trHtmlContent.Style["display"] = "block";
                        trUrl.Style["display"] = "none";
                        EDITOR_WORD.Style["display"] = "none";
                    }
                    else if (sContentType == "3")
                    {
                        tdContentType.InnerText = "链接地址";
                        tdUrl.InnerHtml = (msNews.ConnectAddress != "") ? msNews.ConnectAddress : "&nbsp;";
                        trHtmlContent.Style["display"] = "none";
                        trUrl.Style["display"] = "block";
                        EDITOR_WORD.Style["display"] = "none";
                    }
                    ucAttach.ViewShow("0010", sId);
                }
            }
            string sScriptName = "news_submit_edit.aspx";
            string sServerName = "OfficeServer.aspx";
            string sHttpUrl = "http://" + Request.ServerVariables["HTTP_HOST"] + Request.ServerVariables["SCRIPT_NAME"];
            sHttpUrl = sHttpUrl.Substring(0, sHttpUrl.Length - sScriptName.Length);
            string sServerUrl = sHttpUrl + sServerName;  //获取OfficeServer文件的完整路径
            hdWebUrl.Value = sServerUrl;
        }

        private void InitOffice(string sContentType)
        {
            hdRecordID.Value = "";
            hdTemplate.Value = "";
            if (sContentType == "1")
                hdFileType.Value = ".doc";
            else
                hdFileType.Value = ".xls";
            hdEditType.Value = "0,0";
            hdUserName.Value = "";
        }        
    }
}
